package diamondServer.businesslogic.resource;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

import diamondServer.resources.MessageFake;
import diamondServer.resources.ServiceFake;


import junit.framework.TestCase;

/**
 * Tests MessageFake, ServiceFake and Resource.
 */
public class FakedResourceTest
		extends TestCase
{
	private Resource r;
	private MessageFake m;
	private ServiceFake s;
	
	private final ByteArrayOutputStream out =
		new ByteArrayOutputStream(); //for syso testing
	private final String LINE_SEPARATOR =
		System.getProperty("line.separator");

	protected void setUp() throws Exception
	{
		m = new MessageFake();
		s = new ServiceFake();
		r = new Resource(m,s);
		System.setOut(new PrintStream(out));
	}
	
	@Override
	protected void tearDown() throws Exception
	{
		System.setOut(null); 
	}
	
	public void testServiceProvide()
	{
		s.provide(m);
		assertEquals(m.getBody()+LINE_SEPARATOR, out.toString());
	}
	
	public void testResourceGets()
	{
		assertEquals(r.getMessage(),m);
		assertEquals(r.getService(),s);
	}

}
